<?php
/**
 * A simple description for this script
 *
 * PHP Version 5.2.0 or Upper version
 *
 * @package    Paylog
 * @author     Hidehito NOZAWA aka Suin <http://suin.asia>
 * @copyright  2010 Hidehito NOZAWA
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
 *
 */

class Paylog_Object_BookHandler extends Paylog_Abstract_ObjectHandler
{
	protected $object  = 'Paylog_Object_Book';
	protected $table   = 'book';
	protected $primary = 'id';

	public function loadByUserId($userId)
	{
		$relBookUserHand = new Paylog_Object_RelBookUserHandler;
		$bookIds = $relBookUserHand->getBookIdsByUserId($userId);

		$objs = array();

		foreach ( $bookIds as $bookId )
		{
			$objs[] = $this->load($bookId);
		}

		return $objs;
	}

	public function isBookExists($id)
	{
		$id = intval($id);

		$sql = "SELECT COUNT(`id`) FROM `%s` WHERE `id` = '%u'";
		$sql = sprintf($sql, $this->table, $id);
		$result = $this->db->query($sql);

		list($total) = $this->db->fetchRow($result);

		return ( $total > 0 );
	}
}

?>
